package leetcode.p645;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: trtan
 * @date: 2021-07-04 10:22
 **/
public class SetMismatch {
    public int[] findErrorNums(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int count = map.getOrDefault(nums[i], 0);
            map.put(nums[i], count+1);
        }
        int a = 0, b = 0;
        for (int i = 1; i <= nums.length; i++) {
            int count = map.getOrDefault(i, -1);
            if (count == -1) {
                b = i;
            }
            if (count > 1) {
                a = i;
            }
        }
        return new int[]{a, b};
    }
}
